(function(vc){
    vc.extends({
        propTypes: {
           emitChooseAffiliateRelation:vc.propTypes.string,
           emitLoadData:vc.propTypes.string
        },
        data:{
            chooseAffiliateRelationInfo:{
                affiliateRelations:[],
                _currentAffiliateRelationName:'',
            }
        },
        _initMethod:function(){
        },
        _initEvent:function(){
            vc.on('chooseAffiliateRelation','openChooseAffiliateRelationModel',function(_param){
                $('#chooseAffiliateRelationModel').modal('show');
                vc.component._refreshChooseAffiliateRelationInfo();
                vc.component._loadAllAffiliateRelationInfo(1,10,'');
            });
        },
        methods:{
            _loadAllAffiliateRelationInfo:function(_page,_row,_name){
                var param = {
                    params:{
                        page:_page,
                        row:_row,
                        communityId:vc.getCurrentCommunity().communityId,
                        name:_name
                    }
                };

                //发送get请求
               vc.http.apiGet('affiliateRelation.listAffiliateRelation',
                             param,
                             function(json){
                                var _affiliateRelationInfo = JSON.parse(json);
                                vc.component.chooseAffiliateRelationInfo.affiliateRelations = _affiliateRelationInfo.affiliateRelations;
                             },function(){
                                console.log('请求失败处理');
                             }
                           );
            },
            chooseAffiliateRelation:function(_affiliateRelation){
                if(_affiliateRelation.hasOwnProperty('name')){
                     _affiliateRelation.affiliateRelationName = _affiliateRelation.name;
                }
                vc.emit($props.emitChooseAffiliateRelation,'chooseAffiliateRelation',_affiliateRelation);
                vc.emit($props.emitLoadData,'listAffiliateRelationData',{
                    affiliateRelationId:_affiliateRelation.affiliateRelationId
                });
                $('#chooseAffiliateRelationModel').modal('hide');
            },
            queryAffiliateRelations:function(){
                vc.component._loadAllAffiliateRelationInfo(1,10,vc.component.chooseAffiliateRelationInfo._currentAffiliateRelationName);
            },
            _refreshChooseAffiliateRelationInfo:function(){
                vc.component.chooseAffiliateRelationInfo._currentAffiliateRelationName = "";
            }
        }

    });
})(window.vc);
